package org.breathe.dynamic.thread.pool.core.spring;

import org.breathe.dynamic.thread.pool.core.thread.BreatheDtpExecutor;
import org.breathe.dynamic.thread.pool.core.thread.ThreadPoolBuilder;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 提供一个没有那么复杂的，可操作没有那么高的一个线程池，但是构造简单
 * @author: breathe
 * @createTime: 2025-04-13
 */
public class ThreadPoolCreator {

    /**
     * 构建普通线程池
     * @param threadPrefix 线程的前缀
     * @return 返回一个线程池
     */
    public static ThreadPoolExecutor createCommonFast(String threadPrefix) {
        return ThreadPoolBuilder.newBuilder()
                .threadFactory(threadPrefix)
                .buildCommon();
    }

    /**
     * 构建动态线程池
     */
    public static BreatheDtpExecutor createDynamicFast(String name) {
        return createDynamicFast(name, name);
    }

    /**
     * 构建动态线程池
     */
    public static BreatheDtpExecutor createDynamicFast(String name, String threadPrefix) {
        return ThreadPoolBuilder.newBuilder()
                .threadPoolName(name)
                .threadFactory(threadPrefix)
                .buildDynamic();
    }

    /**
     * 构建受ttl保护的线程池
     */
    public static ExecutorService createCommonWithTtl(String threadPrefix) {
        return ThreadPoolBuilder.newBuilder()
                .threadFactory(threadPrefix)
                .buildWithTtl();
    }
}
